{* $Id$ *}
{include_core file="admin/lib/header.html" title="门店展示"}
<div class="page-header border-bottom clearfix">
  <h2 class="left">{$store_info.user_name}的门店管理<span>编辑门店</span></h2>
  <a href="{if $store_type == 100}{AnUrl("store/admin/movie_store")}{else}{AnUrl("store/admin")}{/if}" class="btn btn-default btn-sm right">&lt;&nbsp;返回门店列表</a>
</div>
<!--start:门店新增-->
<div class="add-form">
  <form class="js_creatForm" action="{AnUrl('store/admin/update')}" method="post" enctype="multipart/form-data">
    <input type="hidden" name="info[id]" value="{$store_info.id}">
    <input type="hidden" name="store_type" value="{$store_type}">
    <table class="table" cellpadding="0" cellspacing="0">
      <tr>
        <th><label for="" class="add-f-label">所属合伙人：</label></th>
        <td>
        {$store_info.dealer_name}
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">服务合伙人：</label></th>
        <td>
            <select placeholder="请选择默认服务合伙人" class="add-f-ipt1" id="suggest_default_service_agency" name="info[service_agency_id]">
                <option value="0"{if $store_info.service_agency_id == 0} selected="selected"{/if}>请选择默认服务合伙人</option>
                {foreach $agency_list as $k => $v}
                <option value="{$v.id}"{if $v.id == $store_info.service_agency_id} selected="selected"{/if}>{$v.realname}({$v.mobile})</option>
                {/foreach}
            </select>
            <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>终端在下单时订单会自动给指派给默认服务合伙人</div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">市场人员：</label></th>
        <td>
            <select placeholder="请选择默认市场人员" class="add-f-ipt1" id="suggest_marketing" name="info[marketing_id]">
                <option value="0"{if $store_info.marketing_id == 0} selected="selected"{/if}>请选择默认市场人员</option>
                {foreach $marketing_list as $k => $v}
                <option value="{$v.id}"{if $v.id == $store_info.marketing_id} selected="selected"{/if}>{$v.realname}({$v.mobile})</option>
                {/foreach}
            </select>
            <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">[谨慎操作]</span>负责送货的默认市场人员，一般情况下无需修改(默认为签约人)，若不设置则会默认为合伙人本人</div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">主店前缀名称：</label></th>
        <td>
        {$store_info.title}
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">门店后缀名：</label></th>
        <td>
          <input name="info[title_branch]" style="width:490px;" class="add-f-ipt1 js_userName" value="{$store_info.title_branch}" >
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">默认仓库地址：</label></th>
        <td>
          <select name="province" class="js_provinceList" style="width:150px;">
              <option value="">请选择省份</option>
          </select>
          <select name="city" class="js_cityList" style="width:150px;display:none">
              <option value="">请选择城市</option>
          </select>
          <select name="county" class="js_countyList" style="width:150px;display:none">
              <option value="">请选择地区</option>
          </select>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">详细地址:</label></th>
        <td>
          <input name="info[address]" style="width:490px;" type="text" value="{$store_info.address}" class="add-f-ipt1">
          <div class="tips"><span style="line-height: 34px;color: #f00;margin-right: 10px;">*</span>输入详细地址</div>
        </td>
      </tr>
      {if $store_info.type == 100}
      <tr>
        <th><label for="" class="add-f-label">门店类型:</label></th>
        <td>
          <select name="movie_type" class="js_movieType" style="width:150px;display:block">
              <option value="">请选择门店类型</option>
              <option value="1"{if $store_info.movie_type==1} selected{/if}>直营</option>
              <option value="2"{if $store_info.movie_type==2} selected{/if}>加盟</option>
              <option value="3"{if $store_info.movie_type==3} selected{/if}>私营</option>
          </select>
        </td>
      </tr>
        {if $store_info.movie_type != 3}
        <tr>
        <th><label for="" class="add-f-label">院线类型:</label></th>
        <td>
          <select name="cinema_type" class="js_cinemaType" style="width:150px;display:block">
              <option value="">请选择院线类型</option>
              {foreach store_config::$cinema_type as $k => $v}
              <option value="{$k}"{if $store_info.cinema_type==$k} selected{/if}>{$v}</option>
              {/foreach}
          </select>
        </td>
      </tr>
        {/if}
        {if !in_array($role_id, array(user_config::MULTIPLE_DIVISION))}
        <tr>
        <th><label for="" class="add-f-label">是否允许赊账:</label></th>
        <td>
              <input type="radio" name="info[is_allow_credit]" value="1"{if $store_info.is_allow_credit==1} checked{/if}>允许</option>&nbsp;&nbsp;
              <input type="radio" name="info[is_allow_credit]" value="0"{if $store_info.is_allow_credit==0} checked{/if}>不允许</option>
        </td>
      </tr>
        {/if}
      {/if}
      <tr>
        <th valign="top"><label class="add-f-label" for="">门头图：</label></th>
        <td class="perUpOuter">
          <div class="clearfix">
            <div class="btn-upload left">
              <a href="javascript:void(0);"><i class="icon-upload"></i>门头图</a>
              <input type="file" class="js_upFile" name="cover">
            </div>
            <!-- <span class="tips left">&nbsp;&nbsp;&nbsp;图片比例：528*333</span> -->
          </div>
          <div class="js_upFileBox">
              <div class="js_upFileBox">
              <img src="{if $store_info.cover}{_image($store_info.cover)}{else}{store_helper::cover($store_info.cover)}{/if}" width="270">
              <!-- <img src="{$smarty.const.SITE_URL}/images/m/default/focus_default.jpg" width="270"> -->
          </div>
          </div>
        </td>
      </tr>
      <tr><th>&nbsp;</th><td class="noborder"><button type="submit" class="btn btn-success js_submit">&nbsp;&nbsp;&nbsp;确认&nbsp;&nbsp;&nbsp;</button></td></tr>
    </table>
  </form>
</div>
<!--end:门店新增-->
<script>

$(function(){
    // 初始化门店编辑页面
    if ("{$store_info.dealer_level}" > 0) {
        $('.js_aboutDealer').slideDown();
        // 设置默认助理
        $('select[name="info[assistant]"]').val('{$store_info.assistant}');
    } else {
        $('.js_aboutDealer').slideUp();
    }
    
    if ($('.js_movieType').val() == 3) {
        $('.js_cinemaType').val('');
        $('.js_cinemaType').parents('tr').slideUp();
    } else {
        $('.js_cinemaType').val('{$store_info.cinemaType}');
        $('.js_cinemaType').parents('tr').slideDown();
    }
    
    {if $store_info.type == 100}
      {if $store_info.movie_type == 1 || $store_info.movie_type == 2}
        {if $store_info.cinema_type}
          $('.js_cinemaType').val('{$store_info.cinema_type}');
        {/if}
      {/if}
    {/if}
    
    
    $('.js_movieType').change(function(){
        if ($(this).val() == 3) {
            $('.js_cinemaType').parents('tr').slideUp();
        } else {
            $('.js_cinemaType').parents('tr').slideDown();
        }
    });
    
  //初始化省份列表
    $.ajax({
      url : 'area/admin/ajax_get_provinces',
      type : 'get',
      dataType : 'json',
      success : function(province_list){
        for (var i in province_list) {
          
          var opt = $('<option value="'+province_list[i]['area_code']+'">'+province_list[i]['area']+'</option>');
          $('.js_provinceList').append(opt);
        }

        {if $area['province_info']}
          $('select[name="province"]').val("{$area.province_info.area_code}");
          
          $('.js_provinceList').change();
          
        {/if}

        {if $area['city_info']}
          $('.js_provinceList').val("{$area.province_info.area_code}");
          
          $('.js_cityList').val("{$area.city_info.area_code}");
          $('.js_cityList').change();
          $('.js_countyList').val("{$area['county_info']['area_code']}");
        {/if}
      }
    });
    
    $('.js_provinceList').change(function(){
        //获取值
        if($(this).val() !== ''){
          var province = $(this).val();
          $('.js_cityList').fadeIn();
          $('.js_countyList').fadeOut();
          $('.js_countyList').val('');
        }else{
          $('.js_cityList').fadeOut();
          $('.js_cityList').val('');
          $('.js_countyList').fadeOut();
          $('.js_countyList').val('');
          
          return false;
        }
        $('.js_cityList').empty();
        $('.js_cityList').append('<option value="">请选择城市</option>');
        $('.js_countyList').empty();
        $('.js_countyList').append('<option value="">请选择区(县)</option>');

        //发送ajax
        $.ajax({
          url : 'area/admin/ajax_get_citys?province_code='+province,
          success : function(city_list){
            for (var i in city_list) {
              var opt = $('<option value="'+city_list[i]['area_code']+'">'+city_list[i]['area']+'</option>');
              $('.js_cityList').append(opt);
            }

            {if $area.city_info}
              $('.js_cityList').val("{$area.city_info.area_code}");
            {/if}
          },
          type : 'get',
          dataType : 'json',
          async : false,
        });


      });
      //城市
      $('.js_cityList').change(function(){
        if ( $('.js_provinceList').val() === '' || $('.js_cityList').val() === '') {
          $('.js_countyList').fadeOut();
          $('.js_countyList').val('');
          return false;
        } else {
          $('.js_countyList').fadeIn();
        }

        $('.js_countyList').empty();
        $('.js_countyList').append('<option value="">请选择区(县)</option>');

        //获取省份的key和值
        var province_code = $('.js_provinceList').val();
        var pro_text = $('.js_provinceList').text();

        //获取城市的值
        var city_code = $(this).val();

        //发送ajax
        $.ajax({
          url : 'area/admin/ajax_get_countys?province_code='+province_code+'&city_code='+city_code,
          type : 'get',
          dataType : 'json',
          success : function(county_list){
            for (var i in county_list) {
              var opt = $('<option value="'+county_list[i]['area_code']+'">'+county_list[i]['area']+'</option>');
              $('.js_countyList').append(opt);
            }

            {if $area['county_info']}
              $('.js_countyList').fadeIn();
              $('.js_countyList').val("{$area['county_info']['area_code']}");
            {/if}
          }
        });
        
      });
    
    
  // 提交验证
  $('.js_submit').click(function(e){
    e.preventDefault();
    
    $('.js_creatForm').submit();
  });
  
//上传图片预览
    $(".js_upFile").change(function(e){
      handleFileSelect($(this), 270);
    });
  
  
});

</script>
{include_core file="module/suggestion.html" id="suggest_default_service_agency"}
{include_core file="module/suggestion.html" id="suggest_marketing"}
{include_core file="admin/lib/footer.html"}